package com.wanli.agent.mine.model;

import com.wanli.agent.appconst.MethodType;
import com.wanli.agent.appconst.URLConst;
import com.wanli.agent.base.DataCallBack;
import com.wanli.agent.bean.BaseResponseBean;
import com.wanli.agent.bean.UserInfoBean;
import com.wanli.agent.retorfit_manager.ResponseObserver;
import com.wanli.agent.retorfit_manager.RetrofitHelper;
import com.wanli.agent.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

public class MineModelImpl implements IMineModel {
    @Override
    public void requestMine(DataCallBack<UserInfoBean> callBack) {
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.ME, null, new ResponseObserver<UserInfoBean>() {
            @Override
            public void onSuccessful(UserInfoBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(UserInfoBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestFeedBack(String content, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("content", content);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.OpinionAdd, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestLoginOut(String id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.LOGINOUT, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestLoginOutAccount(DataCallBack<BaseResponseBean> callBack) {
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.LOGINOUTACCOUNT, null, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestUnBindDeviceId(String client_no, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("client_no", client_no);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.unBindDeviceId, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                callBack.onFailed(msg, code);
                ToastUtil.showShort(msg);
            }
        });
    }
}
